<?php
include_once("db_factory.php");
include_once("obj_acl_action.php");

class dal_acl_action {
	//Modlular level variables
	public $_db;
	
	private $_action_id;

	function dal_acl_action(){
		$this->_db = db_factory::GetInstance();
	}//End User Constructor

	function get($id)
	{
		$obj = new obj_acl_action();
		//Load a User by id
		$SQL = "SELECT * FROM acl_action WHERE action_id= $id ";
		$results = $this->_db->ExecuteQuery($SQL);
		foreach($results as $result)
		{
			// loop through results
			$obj->set_action_id($result['action_id']);
			$obj->set_resource($result['resource']);
			$obj->set_name($result['name']);
			
		}
		return $obj;
	}

	function save(&$obj){
		//Save User - Use EntityID to save
			$SQL = "UPDATE acl_action SET `resource` = '" . $obj->get_resource() ."',`name` = '" . $obj->get_name() ."' WHERE action_id= " . $obj->get_action_id(). "";
			return $this->_db->ExecuteNonQuery($SQL);
	}//End Save
	
	function insert(&$obj)
	{
	
			$SQL = "INSERT INTO acl_action (`resource`,`name`) VALUES ('" . $obj->get_resource() ."','" . $obj->get_name() ."')";
			$this->_db->ExecuteNonQuery($SQL); 
			// After inserting User then load it
			return $this->get($this->_db->GetLastInsertedID());
	}

	function delete($id){
		//Delete User
		$SQL = "DELETE FROM acl_action WHERE action_id= $id ";
		return $this->_db->ExecuteNonQuery($SQL); 
	}//End Delete
	
	function get_all($query=NULL)
	{
	
		if($query !=NULL)
		{
			$SQL = "SELECT * FROM acl_action WHERE " . $query;
		}
		else
		{
			$SQL = "SELECT * FROM acl_action";
		}
		
		$results = $this->_db->ExecuteQuery($SQL);
		
		foreach($results as $result)
		{
			// loop through results
			$temp = new obj_acl_action();
			// loop through results
			
			$temp->set_action_id($result['action_id']);
			
			$temp->set_resource($result['resource']);
			
			$temp->set_name($result['name']);
			
			$buffer[] = $temp;
		}
		
		return $buffer;
	
	}



	/////////////////////////////

	function _dal_acl_action(){
		//Destroys User  DALobject
		$this->_DBManager->Close();
	}//End User DAL Destructor
}//End class
?>
